package com.hancher.common.androidutil;

import android.os.Handler;
import android.os.Message;

/**
 * 定义一个安全的 Handler
 */
public class SafelyHandlerWarpper extends Handler {
    private Handler impl;

    public SafelyHandlerWarpper(Handler impl) {
        this.impl = impl;
    }

    @Override
    public void dispatchMessage(Message msg) {
        // 增加try catch, 防止崩溃
        try {
            super.dispatchMessage(msg);
        } catch (Exception e) {
        }
    }

    @Override
    public void handleMessage(Message msg) {
        // 需要委托给原Handler执行
        impl.handleMessage(msg);
    }
}
